package com.wlzg.collectiontool.util

import android.app.Activity
import com.github.dfqin.grantor.PermissionListener
import com.github.dfqin.grantor.PermissionsUtil

object  PermissionUtil {

    fun requestPermission(
        activity: Activity?,
        per: Array<String>,
        permissionLisenter: PermissionListener?
    ) {
        if (PermissionsUtil.hasPermission(activity!!, *per)) {
            //有访问权限
            permissionLisenter?.permissionGranted(per)
        } else {
            PermissionsUtil.requestPermission(activity, object : PermissionListener {
                override fun permissionGranted(permissions: Array<String>) {
                    //用户授予了权限
                    if (permissionLisenter != null) {
                        permissionLisenter.permissionGranted(permissions)
                    }
                }

                override fun permissionDenied(permissions: Array<String>) {
                    //用户拒绝了申请
                    if (permissionLisenter != null) {
                        permissionLisenter.permissionDenied(permissions)
                    }
                }
            }, *per)
        }
    }
}